import React, { Component } from 'react'
import Input from './Input.jsx'
import Table from './table.jsx'
export default class kp extends Component {
    constructor() {
        super()
        this.state = {
            list: [{ name: '小明', age: 18, id: 4555 }],
            msg: { name: "", age: "" },
            flag: false,
            i: 0
        }
    }
    add = (e) => {
        let arr = this.state.list
        arr.push(e)
        this.setState({
            list: arr
        })
    }
    del = (e) => {
        let arr = this.state.list
        arr.splice(e, 1)
        this.setState({
            list: arr,

        })
    }

    edit = (e) => {
        let arr = this.state.list[e]
        this.setState({
            msg: arr,
            flag: true,
            i: e
        })
    }
    editok = (e) => {
        let arr = this.state.list
        arr[this.state.i] = e
        this.setState({
            list: arr
        })
    }

    flags = () => {
        this.setState({
            flag: false
        })
    }
    render() {
        return (
            <React.Fragment>
                <Input add={this.add} msg={this.state.msg} flag={this.state.flag} editOk={this.editok} flags={this.flags}></Input>
                <Table edit={this.edit} del={this.del} list={this.state.list}></Table>
            </React.Fragment>
        )
    }
}